﻿@using System
@using MZBlog.Core.Documents
@using MZBlog.Core.Extensions
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<MZBlog.Core.Commands.Posts.NewPostCommand>

@{
    ViewBag.Title = "Add new Post";
    Layout = "_AdminLayout.cshtml";
}
<div class="row">
    <ol class="breadcrumb">
        <li><i class="fa fa-dashboard"></i> <a href="~/mz-admin">控制面板</a> </li>
        <li class="active"><i class="fa fa-edit"></i> 发表文章</li>
    </ol>
</div>
<div class="row">
    <form method="post" role="form" action="~/mz-admin/posts/new">
        <div class="form-group">
            <input id="post-title" type="text" class="form-control" name="Title" placeholder="标题" value="@Model.Title" required />
        </div>
        <div class="form-group">
            <input id="post-slug" type="text" class="form-control" name="TitleSlug" placeholder="固定链接Key" value="@Model.TitleSlug" required />
        </div>
        <div class="form-group">
            <textarea id="post-content" data-provide="markdown" rows="30" name="MarkDown" placeholder="内容" required>@Model.MarkDown</textarea>
        </div>
        <div class="form-group">
            <input name="Tags" id="tags" class="form-control" value="@Model.Tags" />
        </div>
        <div class="form-group">
            <label for="pubdate">发布时间(UTC):</label>
            <input id="pubdate" name="PubDate" value="@(Model.PubDate != DateTime.MinValue ? Model.PubDate : DateTime.UtcNow)" />
            &loz;
            <label for="published">发布</label>
            <input id="published" name="Published" value="true" type="checkbox" />

            <input type="submit" value="保存" class="btn btn-primary pull-right" />
        </div>
    </form>
</div>
@section PostScripts{
    <script src="~/scripts/jquery.tagsinput.js"></script>
    <script src="~/scripts/markdown.js"></script>
    <script>
        $('#tags').tagsInput({ 'width': '100%', 'defaultText': '添加标签' });
        $('#post-title').on('change', function () {
            var _title = $(this).val();
            if ($("#post-slug").val() == "") {
                $.post("/mz-admin/slug", { title: _title }, function (data) {
                    $("#post-slug").val(data);
                });
            }
        });
    </script>
}